import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';

import '../../viewmodel/scheduling/work_scheduling_info_view_model.dart';

class WorkSchedulingInfoPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _WorkSchedulingInfoState();
}

class _WorkSchedulingInfoState
    extends BaseMvvmState<WorkSchedulingInfoViewModel, WorkSchedulingInfoPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            IconButton(
                onPressed: () {
                  viewModel.backClick();
                },
                icon: Icon(Icons.arrow_back_ios)),
            CommonText(
              viewModel.monthStr,
              textSize: 17,
              fontWeight: FontWeight.bold,
            ).addToContainer(width: 120, alignment: Alignment.center),
            IconButton(
                onPressed: () {
                  viewModel.nextClick();
                },
                icon: Icon(Icons.arrow_forward_ios)),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: ["一", "二", "三", "四", "五", "六", "七"]
              .map((e) => CommonText(e))
              .toList(),
        ).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16)),
        Container(
          height: 10,
        ),
        GridView.count(
          crossAxisCount: 7,
          crossAxisSpacing: 6,
          mainAxisSpacing: 6,
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          padding: EdgeInsets.symmetric(horizontal: 16),
          children: viewModel.dateList.map((e) {
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                CommonText(e.day,
                    textColor: e.inMonth
                        ? !e.scheduleStatus.isNullOrEmpty()
                            ? Colors.white
                            : Colors.black
                        : Colors.grey),
                Container(
                  height: 2,
                ),
                CommonText(e.scheduleStatus, textSize: 12,textColor: !e.scheduleStatus.isNullOrEmpty()
                    ? Colors.white
                    : Colors.black,textAlign: TextAlign.center)
              ],
            ).addToContainer(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: !e.scheduleStatus.isNullOrEmpty()
                        ? Colors.blue
                        : Colors.transparent,
                    shape: BoxShape.circle));
          }).toList(),
          childAspectRatio: viewModel.dateList.length > 35 ? 1 : 0.82,
        ),


      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    var staffName = vm?.userName??"";
    return Scaffold(
      appBar: AppBar(
        title: Text(staffName.isNullOrEmpty()?"排班信息":"${staffName}的排班信息"),
        actions: [
          IconButton(onPressed: (){
            viewModel.chooseStaff();
          }, icon: Icon(Icons.change_circle_outlined))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  WorkSchedulingInfoViewModel createViewModel() {
    return WorkSchedulingInfoViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }
}
